#pragma once


#if _IS_UI_DESIGNED_ENABLED_


#include <IXTracker.h>
#include "../../Skin/Source/XFrameImpl.h"


enum TrackerHitCode
{
    TrHit_None  = 0x00,
    TrHit_Left  = 0x01,
    TrHit_Top   = 0x02,
    TrHit_Right = 0x04,
    TrHit_Bottom= 0x08,
    TrHit_Center= 0x10,
};


template <class I>
class CXTrackerImpl : public CXFrameImpl<I>
{
    typedef CXFrameImpl<I> superclass;

    BEGIN_DEF_SKIN_CLASS(CXTracker, superclass, gs_strGuidXSkin)
        IMP_BASIC_INTF(IXTracker,    0)
    END_DEF_SKIN_CLASS();

    IMPL_CONTROL_OBJ(CXTrackerImpl, superclass, _T("Tracker"));

public:
    CXTrackerImpl();
    virtual ~CXTrackerImpl();

public:
    // IXTracker
    virtual HRESULT STDMETHODCALLTYPE put_Trackee(IN IXFrame* pTrackee);

public:
    // IXFrame
    virtual HCURSOR STDMETHODCALLTYPE GetCursor(IN POINT* pt);
    virtual BOOL STDMETHODCALLTYPE   OnMouseDown(POINT* pt);
    virtual BOOL STDMETHODCALLTYPE   OnMouseUp(POINT* pt);

    virtual BOOL STDMETHODCALLTYPE   OnMouseMove(IN POINT* pt);
    virtual BOOL STDMETHODCALLTYPE   OnMouseHover(POINT* pt);
    virtual BOOL STDMETHODCALLTYPE   OnMouseLeave(POINT* pt);

    virtual void STDMETHODCALLTYPE   OnCaptureLost();

    virtual void STDMETHODCALLTYPE   PostDraw(XCANVAS xCanvas, const RECT& rcDraw);

public:
    // IXControl
    virtual void    STDMETHODCALLTYPE   GetAutoSize(OUT LPSIZE pAutoSize);
    virtual HRESULT STDMETHODCALLTYPE   GetItemByPt(POINT& pt, IXControl** ppItem);

public:
    // IXBaseObj
    virtual void STDMETHODCALLTYPE   OnFinalRelease();

protected:
    // CXFrameImpl
    void            ReleaseData();
    virtual BOOL    OnClicked(const POINT* pt);
    virtual BOOL    OnRightClicked(const POINT* pt);
    virtual void    OnSizeChanged();

protected:
    // CXTrackerImpl
    DWORD           HitTest(const POINT* pt);
    void            AdjustTrackee(const POINT* pt);

protected:
    IXFrame*    m_pTrackee;
    DWORD       m_HitCode;
    POINT       m_ptOrg;
};


class CXTracker : public CXTrackerImpl<IXTracker>
{
};



#endif // _ENABLE_UI_DESIGNER_
